Building a Tip of the Day Application (Part 3): Submitting Tips to the Web Service
Table of Contents
Binding Data to the Submit a Tip Interface
Adding the "submit a tip" feature is actually fairly simple
because it only takes five parameters (AuthorName_txt, AuthorEmail_txt,
AuthorURL_txt, TipTitle_txt and TipText_txt) and sends them
to the web service. Since this web service does not return any variables,
it is easy to set up because it only needs a handful of bindings and
one behavior.
Create the web service for submitting tips as follows:
- With the presentation screen selected, open the Web Services
panel (Ctrl+Shift+F10) and expand the
tipServiceweb service. - Right-click the
submitTipmethod. Select Add Method Call from the contextual menu. This adds a new instance of the WebServiceConnector component to the Stage. - Drag the new WebServiceConnector instance off the Stage with the
other data components and assign it an instance name of
submitTip_wsc.
Bind the parameters of the tip submission web service to interface items (components) on the submit screen:
-
In the Bindings tab of the Component Inspector panel, add five bindings (one for each of the parameters). To do this, click the Add Binding button (+) in the Component Inspector panel’s Bindings tab. In the Add Binding window, select each parameter and click OK to add the binding. When you’re done, the Bindings tab should look as it does below in Figure 1.
Figure 1. Data bindings in the Component Inspector panel
- Select the
params.AuthorNamebinding. Double-click the Value column next to bound to in the Name/Value section below the binding listings. The Bound To dialog box opens. - In the lower screen, double-click the value box to the
right of bound to. In the Bound To dialog box, navigate
to the submit screen and choose
TextInput, <AuthorName_txt>. This sets the Component path, addingtext : Stringto the Schema location pane. (See Figure 2.) - Press OK to bind the
params.AuthorNamedata object to its corresponding component in the submit screen. -
Repeat the process for
AuthorEmail,AuthorURL,TipTitleandTipText, changing the component path accordingly.

Figure 2. Binding params.AuthorName to the AuthorName_txt TextInput component instance on the submit screen.
Now, activate the submit button so it triggers the web service and redirects the user to the submitthankyou screen:
- Click the submit screen and select the Submit button on the Stage.
- In the Behaviors panel, click the Add Behavior button (+), then
select Data > Trigger Data Source from the contextual menu. Select
the
submitTip_wsccomponent and click OK.
Test the application (Control-Enter). As you test, do the following:
- Enter a tip and press the Submit button. The web service sends an e-mail to the administrator with the data entered into the text fields.
- Press the "back" button on the thank you page. Notice that the values entered by the visitor remain in the text fields.
The final point can be annoying to users who want to add another tip; they probably don't want to have to delete the old tip values manually. When users click the back button, you will want to clear the existing form values for TipTitle_txt and TipText_txt. You can leave the person’s name, e-mail, and URL in the form fields because the user may reuse those values.
Here's a method for doing this as part of the on (click) script
for the Back button. You could also clear the form variables using
an on (reveal) on the submitthankyou screen directly
if you prefer. Each way of accomplishing this task has advantages and
disadvantages.
Select the Back button on the submitthankyou screen. Add
the following code to the top of Actions panel, after the on
(click) { as follows:
this._parent._parent.submit.TipTitle_txt.text = ""; this._parent._parent.submit.TipText_txt.text = "";
You can find these paths by using the Insert a target path button
in the Actions panel and clicking the instance you want. Now after
someone submits a tip and hits the Back button, the application clears
out the values for TipTitle_txt and TipText_txt.